Page({
  /**
   * 页面的初始数据
   */
  data: {
    emptyType: false,
    getdata: [],
    page: 1,
    limit: 20,
    key: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(){
    this.getKey()
},
getKey() {
  let that = this
  wx.cloud.callFunction({
    name: 'getKey',
    data: {
      name: 'puhaha'
    }
  }).then(res => {
    console.log(res.result.data[0].key)
    that.setData({
      key: res.result.data[0].key
    })
    this.getData()
  })
},

  getData() {
    wx.showLoading({
      title: '加载中',
    });
    let that = this
    var date = Date.parse(new Date())/1000;
    console.log(date)
    wx.request({
      url: "https://v.juhe.cn/joke/content/list.php?key="+that.data.key+"&page="+that.data.page+"&pagesize="+that.data.limit+"&sort=desc&time=" + date,
      data: {
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res)
        wx.hideLoading();
        if (res.statusCode == 200) {
          that.setData({
            emptyType: true,
            getdata: res.data.result.data
          })
        } else {
          that.setData({
            emptyType: false
          })
        }
      },
      fail(res){
        console.log(res)
      }
    })
  },
  // 跳转详情页
  godetails(e) {
    console.log(e.currentTarget.dataset.id)
    wx.navigateTo({
      url: './details?id=' + e.currentTarget.dataset.id,
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onReachBottom(){
    var that=this
    this.setData({
      page: that.data.page+1
    })
    this.getData()
  }
})